package logic

import (
	"context"
	"errors"
	"house_srv/models/mysql"

	"house_srv/housesrv"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddHouseLogic {
	return &AddHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddHouseLogic) AddHouse(in *housesrv.AddHouseRequest) (*housesrv.AddHouseResponse, error) {
	// todo: add your logic here and delete this line
	var house = mysql.House{
		Name:    in.Name,
		Address: in.Address,
		Types:   in.Types,
		Size:    float64(in.Size),
		Price:   float64(in.Price),
	}
	err := house.AddHouse()
	if err != nil {
		logx.Error("房源发布失败")
		return nil, errors.New("房源发布失败")
	}
	return &housesrv.AddHouseResponse{Id: int64(house.ID)}, nil
}
